package com.eduadmin.controller;

import com.eduadmin.entity.Page;
import com.eduadmin.entity.TeamCourseMedian;
import com.eduadmin.service.ITeamCourseMedianService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
public class TeamCourseMedianController {
    private final ITeamCourseMedianService teamCourseMedianService;
    @Autowired
    public TeamCourseMedianController(ITeamCourseMedianService teamCourseMedianService) {
        this.teamCourseMedianService = teamCourseMedianService;
    }
    @RequestMapping(value = "getQueTeamCourseMedian")
    @ResponseBody
    public Map<String, Object> getQueTeamCourseMedian(
            @RequestParam(value = "page", required = false) String page,
            @RequestParam(value = "rows", required = false) String rows,
            @RequestParam("gradeName") String gradeName,
            @RequestParam("semesterName") String semesterName,
            @RequestParam("examName") String examName,
            @RequestParam("categoryName") String categoryName){

        Page pageBean = new Page(Integer.parseInt(page), Integer.parseInt(rows));
        Map<String, Object> reMap = new HashMap<>();                 //查询结果map
        Map<String, Object> paraMap = new HashMap<>();           //查询参数map
        paraMap.put("offset", pageBean.getOffset());
        paraMap.put("rows", pageBean.getRows());
        paraMap.put("gradeName",gradeName);
        paraMap.put("semesterName",semesterName);
        paraMap.put("examName",examName);
        paraMap.put("categoryName",categoryName);

        List<TeamCourseMedian> teamCourseMedianList=teamCourseMedianService.getQueTeamCourseMedianByParams(paraMap);

        paraMap.clear();
        paraMap.put("gradeName",gradeName);
        paraMap.put("semesterName",semesterName);
        paraMap.put("examName",examName);
        paraMap.put("categoryName",categoryName);
        int total = teamCourseMedianService.getTeamCourseMedianNumberByParams(paraMap);
        reMap.put("rows", teamCourseMedianList);
        reMap.put("total", total);
        return reMap;
    }

}
